package com.hk.springtrains.websocket;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

/**
 * 由于部分浏览器对WebSocket的支持较差，使用sockJS模拟WebSocket通信
 */
@EnableWebSocket
public class WebSocketConfigWithSockJS implements WebSocketConfigurer {

    @Autowired
    private WebSocketHandler handler;


    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
            registry.addHandler(handler,"/socket").withSockJS();
    }
}
